/*******************************************************************************
 * 
 * Copyright:
 * 
 * License:
 * 
 * Authors:
 * 
 ******************************************************************************/

/*******************************************************************************
 * 
 * #asset(ui_mov/*) #asset(qx/mobile/icon/${qx.mobile.platform}/*)
 * #asset(qx/mobile/icon/common/*)
 * 
 ******************************************************************************/

/**
 * This is the main application class of your custom application "ui_mov"
 */
qx.Class.define("ui_mov.views.noticiasroot", {
	extend : qx.ui.mobile.page.NavigationPage,
	construct : function() {
		this.base(arguments);
		this.set({
					title : "Noticias", // will be replaced by username
					showBackButton : true,
					backButtonText : "Volver"
				});
		var list = new qx.ui.mobile.list.List({
					configureItem : function(item, data, row) {
						item.setTitle(data.nombre);
						item.setSubtitle(data.descripcion);
						item.setSelectable(true);
					}
				});
		this.list = list;
		list.setModel(new qx.data.Array([]));
		
		list.addListener("changeSelection", function(evt) {
					var tema = list.getModel().getItem(evt.getData());
					window.pages.noticias.setTitle(tema.nombre);
					window.pages.noticias.load(tema.idTema);
					window.pages.noticias.show();					
				}, this);
		this.addListener('start', this.refreshlist, this);

		this.addListener("back", function() {
					window.pages.welcome.show({
								reverse : true
							});
				}, this);
		this.add(list);
	},
	members : {
		refreshlist : function() {
			window.pages.busy.show();
			var req = new qx.io.request.Xhr("/rpc/intereses/listarCliente");
			req.addListener("success", function(e) {
						var res = e.getTarget().getResponse();
						this.list.setModel(new qx.data.Array(res));
						window.pages.busy.hide();
					}, this);
			req.send();
		}
	}
});
